import 'package:get/get.dart';
import 'package:getx_scaffold/common/index.dart';
import 'package:oramemo/core/controllers/transaction_controller.dart';
import 'package:oramemo/entity/create_order_entity.dart';
import 'package:oramemo/entity/membr_level_entity.dart';
import 'package:oramemo/common/langs/text_key.dart';

class SubscriptionLogic extends GetxController {
  TransactionController controller = Get.find();

  bool isAgreed = false;
  MembrLevelData? checkData;

  @override
  void onInit() {
    _requestData();
    super.onInit();
  }

  void _requestData() async {
    await controller.fetchMemberLevels();
    update();
  }

  Future<void> createOrder() async {
    if (checkData?.id == null) {
      Toast.show(TextKey.subscriptionSelectPlan.tr);
      return;
    }
    if (!isAgreed) {
      Toast.show(TextKey.subscriptionAgreement.tr);
      return;
    }
    CreateOrderData? data =
        await controller.createOrder(memberLevelId: checkData!.id!.toString());
  }

  @override
  void onClose() {}
}
